target("bootblock")
    set_kind("binary")
    set_toolchains("x86-tc")
    set_filename("bootblock.elf")
   
    add_cflags(
        "-m32",
        "-O2",
        "-fno-builtin",
        "-nostdinc",
        "-fno-pic -static",
        "-fno-pie -no-pie",
        "-fno-omit-frame-pointer",
        "-fno-strict-aliasing",
        "-fno-stack-protector",
        "-Wall -MD -ggdb -Werror",{force = true}
        )

    add_asflags(
        "-m32",
        "-O2",
        "-fno-builtin",
        "-nostdinc",
        "-fno-pic -static",
        "-fno-pie -no-pie",
        "-fno-omit-frame-pointer",
        "-fno-strict-aliasing",
        "-fno-stack-protector",
        "-Wall -MD -ggdb -Werror",{force = true}
        )

    add_ldflags(
        "-m elf_i386",
        "-N -e start -Ttext 0x7C00",{force = true}
        )
    
    -- bootblock
    add_files(
        "../../arch/x86/boot/bootasm.S",
        "../../arch/x86/boot/bootmain.c"
        )

    -- drivers
    add_files(
        "../../drivers/block/ide/ide.c"
        )

    add_includedirs(
        "../../arch",
        "../../arch/x86",
        "../../drivers",
        "../../kernel/include"
        )

    after_build(function(target)
        -- os.exec("objdump -S %s > bootblock.asm", target:targetfile())
        os.exec("objcopy -S -O binary -j .text -j .rodata %s bootblock", target:targetfile())
        
        -- 将 bootblock 最后两个字节填充为 0x55aa，保证 bootblock 大小为 512B
        os.exec("./sign.pl bootblock")
    end)
    
    after_clean(function(target)
        os.exec("rm bootblock")
    end)
target_end()